Skip to content

feat: port rule valid-typeof#520

Open
fansenze wants to merge 1 commit intomainfrom
feat/port-rule-valid-typeof-20260317
Open

feat: port rule valid-typeof#520
fansenze wants to merge 1 commit intomainfrom
feat/port-rule-valid-typeof-20260317

Conversation

@fansenze
Copy link
Copy Markdown
Contributor

@fansenze fansenze commented Mar 17, 2026

Summary

Port the valid-typeof rule from ESLint to rslint.

Enforce comparing typeof expressions against valid strings

Related Links

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request integrates the valid-typeof rule into rslint, directly adapting it from ESLint. The primary goal is to enhance code quality and prevent runtime errors by ensuring that JavaScript's typeof operator is used correctly in comparisons, specifically by validating that it's only compared against its predefined set of string results. This addition improves the linter's ability to catch subtle type-related bugs early in the development cycle.

Highlights

  • New Rule: valid-typeof: The valid-typeof ESLint rule has been ported to rslint, enforcing that typeof expressions are compared against valid string literals.
  • Rule Logic Implementation: The core logic for the valid-typeof rule has been implemented, including checks for equality operators and an optional requireStringLiterals setting for stricter comparisons.
  • Comprehensive Testing and Documentation: Dedicated Go-based unit tests, JavaScript-based RuleTester tests, and detailed markdown documentation have been added for the new valid-typeof rule.
Changelog
  • internal/config/config.go
    • Imported the valid_typeof rule package.
    • Registered the valid-typeof rule in the global rule registry.
  • internal/rules/valid_typeof/valid_typeof.go
    • Added the core implementation of the valid-typeof rule.
    • Defined validTypes map for typeof operator results.
    • Implemented logic to check equality operators and report invalid comparisons.
    • Included an option requireStringLiterals to enforce stricter comparisons.
  • internal/rules/valid_typeof/valid_typeof.md
    • Added documentation for the valid-typeof rule, including rule details, examples of correct and incorrect code, and options.
  • internal/rules/valid_typeof/valid_typeof_test.go
    • Added Go-based unit tests for the valid-typeof rule, covering valid and invalid cases, including options.
  • packages/rslint-test-tools/rstest.config.mts
    • Updated the test configuration to include the new valid-typeof.test.ts file.
  • packages/rslint-test-tools/tests/eslint/rules/snapshots/valid-typeof.test.ts.snap
    • Added snapshot test results for the valid-typeof rule.
  • packages/rslint-test-tools/tests/eslint/rules/valid-typeof.test.ts
    • Added JavaScript-based tests for the valid-typeof rule using RuleTester.
Activity
  • No human activity (comments, reviews) has been recorded yet for this pull request.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request ports the valid-typeof rule from ESLint. The implementation is solid and well-tested, covering various edge cases and options like requireStringLiterals. The documentation is also clear and helpful.

I've left a couple of suggestions for improvement: one for a small refactoring in the Go rule implementation to follow language idioms, and another to clean up a redundant entry in the test configuration. Overall, great work on porting this rule.

@fansenze fansenze force-pushed the feat/port-rule-valid-typeof-20260317 branch 2 times, most recently from a5376c5 to d2a6d0e Compare March 17, 2026 10:29
@fansenze fansenze force-pushed the feat/port-rule-valid-typeof-20260317 branch 4 times, most recently from e7deb90 to 68eb0c5 Compare March 18, 2026 02:58
@fansenze fansenze force-pushed the feat/port-rule-valid-typeof-20260317 branch 2 times, most recently from 26b4494 to c9ad0bf Compare April 9, 2026 11:36
@fansenze fansenze force-pushed the feat/port-rule-valid-typeof-20260317 branch from c9ad0bf to fa56c89 Compare April 9, 2026 11:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant